package com.zmn.mcc.permit.client.boot.autoconfigure;

import com.zmn.base.common.data.dubbo.interfaces.company.CompanyListRemoteService;
import com.zmn.mcc.dubbo.dto.DubboConsts;
import com.zmn.mcc.dubbo.interfaces.staff.StaffPermitRemoteService;
import com.zmn.mcc.permit.client.aop.ControllerPermitDataAspect;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

/**
 * controller 数据权限的 自动装配类
 * @author LuJia
 * @version v1.0
 * @since 2020/06/22 18:11
 **/
@Configuration
//@ConditionalOnBean(annotation = EnableControllerPermitData.class)
@ConditionalOnProperty(
        name = {"dpermit.controller.enabled"},
        havingValue = "true",
        matchIfMissing = false
)
@Order(-1)
@Slf4j
public class ControllerPermitDataAutoConfiguration {

    @DubboReference(version = DubboConsts.INTERFACE_VERSION, check = false)
    StaffPermitRemoteService staffPermitRemoteService;

    @DubboReference(version = DubboConsts.INTERFACE_VERSION, check = false)
    CompanyListRemoteService companyListRemoteService;

    @Bean
    public ControllerPermitDataAspect controllerPermitDataAspect(){
        log.info("实例化 ControllerPermitDataAspect success --------------------------------------------");
        return new ControllerPermitDataAspect(staffPermitRemoteService, companyListRemoteService);
    }

    public ControllerPermitDataAutoConfiguration() {
        log.info("加载 controller 数据权限装配类 --------------------------------------------");
    }
}
